package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.DwBaiduOpenTempDao;
import com.fdb.efp.nls.service.domain.DwBaiduOpenTemp;
import com.fdb.efp.nls.service.facade.DwBaiduOpenTempService;
import com.fdb.efp.nls.service.vo.DwBaiduOpenTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;


/**
 * Service Impl: 百度联合贷-贷款每日放款明细临时表服务实现
 * @author ligm
 * @date 2019-05-02 
 */
@Service("dwBaiduOpenTempService")
public class DwBaiduOpenTempServiceImpl implements DwBaiduOpenTempService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(DwBaiduOpenTempServiceImpl.class);

	@Autowired
	private DwBaiduOpenTempDao dwBaiduOpenTempDao;

   	/**
	 * 新增数据 
     * @param inDwBaiduOpenTempVo
     * @return 
	 */
	public int insertDwBaiduOpenTemp(DwBaiduOpenTempVO inDwBaiduOpenTempVo) {
		logger.debug("当前新增数据为:"+ inDwBaiduOpenTempVo.toString());
		int num = 0;
		try {
			DwBaiduOpenTemp dwBaiduOpenTemp = new DwBaiduOpenTemp();
			beanCopy(inDwBaiduOpenTempVo, dwBaiduOpenTemp);
			num = dwBaiduOpenTempDao.insertDwBaiduOpenTemp(dwBaiduOpenTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

    /**
	 * 根据主键删除信息 
	 * @param inDwBaiduOpenTempVo
 	 * @return
	 */
	public int deleteByPk(DwBaiduOpenTempVO inDwBaiduOpenTempVo) {
		logger.debug("当前删除数据条件为:"+ inDwBaiduOpenTempVo);
		int num = 0;
		try {
			DwBaiduOpenTemp dwBaiduOpenTemp = new DwBaiduOpenTemp();
			beanCopy(inDwBaiduOpenTempVo, dwBaiduOpenTemp);
			num = dwBaiduOpenTempDao.deleteByPk(dwBaiduOpenTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inDwBaiduOpenTempVo +"删除的数据条数为"+ num);
		return num;
	}


    /**
	 * 根据主键更新信息 
	 * @param inDwBaiduOpenTempVo
	 * @return 
	 */  
	public int updateByPk(DwBaiduOpenTempVO inDwBaiduOpenTempVo) {
		logger.debug("当前修改数据为:"+ inDwBaiduOpenTempVo.toString());
		int num = 0;
		try {
			DwBaiduOpenTemp dwBaiduOpenTemp = new DwBaiduOpenTemp();
			beanCopy(inDwBaiduOpenTempVo, dwBaiduOpenTemp);
			num = dwBaiduOpenTempDao.updateByPk(dwBaiduOpenTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inDwBaiduOpenTempVo +"修改的数据条数为"+ num);
		return num;
	}
	
    /**
	 * 根据主键查询详情 
	 * @param dwBaiduOpenTemp
	 * @return 
	 */
	public DwBaiduOpenTempVO queryByPk(DwBaiduOpenTempVO inDwBaiduOpenTempVo) {
		
		logger.debug("当前查询参数信息为:"+ inDwBaiduOpenTempVo);
		try {
			DwBaiduOpenTemp queryDwBaiduOpenTemp = new DwBaiduOpenTemp();
			beanCopy(inDwBaiduOpenTempVo, queryDwBaiduOpenTemp);
			DwBaiduOpenTemp queryRslDwBaiduOpenTemp = dwBaiduOpenTempDao.queryByPk(queryDwBaiduOpenTemp);
			if (Objects.nonNull(queryRslDwBaiduOpenTemp)) {
				DwBaiduOpenTempVO outDwBaiduOpenTempVo = beanCopy(queryRslDwBaiduOpenTemp, new DwBaiduOpenTempVO());
				logger.debug("当前查询结果为:"+ outDwBaiduOpenTempVo.toString());
				return outDwBaiduOpenTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


    /**
	 * 一级数据权限 
	 * @param dwBaiduOpenTemp
	 * @return 
	 */	
	@SuppressWarnings("unchecked")
	public List<DwBaiduOpenTempVO> queryAllByLevelOne(DwBaiduOpenTempVO dwBaiduOpenTempVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<DwBaiduOpenTempVO> list = null;
		try {
			List<DwBaiduOpenTemp> dwBaiduOpenTemps = dwBaiduOpenTempDao.queryAllByLevelOneByPage(dwBaiduOpenTempVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ dwBaiduOpenTemps.size());
			pageSet(dwBaiduOpenTemps, dwBaiduOpenTempVo);
			list = (List<DwBaiduOpenTempVO>) beansCopy(dwBaiduOpenTemps, DwBaiduOpenTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 二级数据权限 
	 * @param dwBaiduOpenTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduOpenTempVO> queryAllByLevelTwo(DwBaiduOpenTempVO dwBaiduOpenTempVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<DwBaiduOpenTemp> dwBaiduOpenTemps = dwBaiduOpenTempDao.queryAllByLevelTwoByPage(dwBaiduOpenTempVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+dwBaiduOpenTemps.size());
		List<DwBaiduOpenTempVO> list = null;
		try {
			pageSet(dwBaiduOpenTemps, dwBaiduOpenTempVo);
			list = (List<DwBaiduOpenTempVO>) beansCopy(dwBaiduOpenTemps, DwBaiduOpenTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 三级数据权限 
	 * @param dwBaiduOpenTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduOpenTempVO> queryAllByLevelThree(DwBaiduOpenTempVO dwBaiduOpenTempVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<DwBaiduOpenTemp> dwBaiduOpenTemps = dwBaiduOpenTempDao.queryAllByLevelThreeByPage(dwBaiduOpenTempVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ dwBaiduOpenTemps.size());
		List<DwBaiduOpenTempVO> list = null;
		try {
			pageSet(dwBaiduOpenTemps, dwBaiduOpenTempVo);
			list = (List<DwBaiduOpenTempVO>) beansCopy(dwBaiduOpenTemps, DwBaiduOpenTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 四级数据权限  
	 * @param dwBaiduOpenTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduOpenTempVO> queryAllByLevelFour(DwBaiduOpenTempVO dwBaiduOpenTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduOpenTemp> dwBaiduOpenTemps = dwBaiduOpenTempDao.queryAllByLevelFourByPage(dwBaiduOpenTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ dwBaiduOpenTemps.size());
		List<DwBaiduOpenTempVO> list = null;
		try {
			pageSet(dwBaiduOpenTemps, dwBaiduOpenTempVo);
			list = (List<DwBaiduOpenTempVO>) beansCopy(dwBaiduOpenTemps, DwBaiduOpenTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 五级数据权限  
	 * @param dwBaiduOpenTemp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduOpenTempVO> queryAllByLevelFive(DwBaiduOpenTempVO dwBaiduOpenTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduOpenTemp> dwBaiduOpenTemps = dwBaiduOpenTempDao.queryAllByLevelFiveByPage(dwBaiduOpenTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ dwBaiduOpenTemps.size());
		List<DwBaiduOpenTempVO> list = null;
		try {
			pageSet(dwBaiduOpenTemps, dwBaiduOpenTempVo);
			list = (List<DwBaiduOpenTempVO>) beansCopy(dwBaiduOpenTemps, DwBaiduOpenTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

	 /**
		 * 根据订单号查找贷款每日放款明细临时信息<br>
		 * 0.1: weijj:2019年5月7日 下午3:02:37:新增 <br>
		 * @author  weijj
		 * @since 2019年5月7日 下午3:02:37
		 * @date 2019年5月7日 下午3:02:37
		 * @version 0.1 
		 */
	@Override
	public DwBaiduOpenTempVO queryByOrderId(DwBaiduOpenTempVO dwBaiduOpenTempVo) {
		// TODO Auto-generated method stub
		
		logger.debug("当前查询参数信息为:"+ dwBaiduOpenTempVo);
		try {
			DwBaiduOpenTemp queryDwBaiduOpenTemp = new DwBaiduOpenTemp();
			beanCopy(dwBaiduOpenTempVo, queryDwBaiduOpenTemp);
			DwBaiduOpenTemp queryRslDwBaiduOpenTemp = dwBaiduOpenTempDao.queryByOrderId(queryDwBaiduOpenTemp);
			if (Objects.nonNull(queryRslDwBaiduOpenTemp)) {
				DwBaiduOpenTempVO outDwBaiduOpenTempVo = beanCopy(queryRslDwBaiduOpenTemp, new DwBaiduOpenTempVO());
				logger.debug("当前查询结果为:"+ outDwBaiduOpenTempVo.toString());
				return outDwBaiduOpenTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 
	 * 统计【贷款每日放款明细临时表】数据量 <br>
	 * 0.1:weijj:2019年5月7日 下午2:37:18:新增 <br>
	 * 
	 * @author weijj
	 * @since 2019年5月7日 下午2:37:18
	 * @date 2019年5月7日 下午2:37:18
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		// TODO Auto-generated method stub
		String msg1 = "查询【贷款每日放款明细临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = dwBaiduOpenTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【贷款每日放款明细临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}

	 /**
		 * 
		 * 分页查询【贷款每日放款明细临时表】 <br>
		 * 0.1:weijj:2019年5月7日 下午2:37:18:新增 <br>
		 * 
		 * @author weijj
		 * @since 2019年5月7日 下午2:37:18
		 * @date 2019年5月7日 下午2:37:18
		 * @version 0.1
		 */
	@SuppressWarnings("unchecked")
	@Override
	public List<DwBaiduOpenTempVO> queryByPage(DwBaiduOpenTempVO dwBaiduOpenTempVO) {
		// TODO Auto-generated method stub
		String msg1 = "贷款每日放款明细临时表";
		logger.debug(msg1, "message {}");
		List<DwBaiduOpenTempVO> list = null;
		try {
			List<DwBaiduOpenTemp> DwBaiduOpens = dwBaiduOpenTempDao.queryByPage(dwBaiduOpenTempVO);
			list = (List<DwBaiduOpenTempVO>) beansCopy(DwBaiduOpens, DwBaiduOpenTempVO.class);

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}
}
